function [bitsTx, dataBuffer, HARQ] = WiSiL_Tx_source(dataBuffer,numberOfGeneratedBits, harqParams, HARQ, transmitterBuffer)
% SOURCE Generates new data.
%   This function generates new data as a binary column vector.
%   
%



ACK = HARQ.acknowledgment;
rep = HARQ.repetitions;
maximum = harqParams.numMaxRepetition;


temp = find(ACK == 1, 1);


if isempty(temp)
    bitsTx = dataBuffer(1: numberOfGeneratedBits);
    dataBuffer( 1: (numberOfGeneratedBits)) = [];
    rep = ones(size(rep));
else
    block = zeros(size(ACK,2));
    for k = 1: size(ACK,2)
        if (ACK(k) == 1 && rep(k) < maximum)
            block{k,1} = transmitterBuffer{k,1};
            rep(k) = rep(k)+1;
            
        else
            block{k,1}(1,:) = dataBuffer(1: length(transmitterBuffer{k,1}));
             dataBuffer(1: length(transmitterBuffer{k,1})) = [];
             rep(k)=1;
        end
     
    end

    
bitsTx = blockConcatenation(block);  
    
end


HARQ.repetitions = rep;
